# -*- coding:utf-8 -*-
"""
@Time : 2021/3/16 00:21
@Author: langengel
@Des: 服务商API
"""
from fastapi import APIRouter, Security
from Authorization.auth import permissions
from application.common.common import refresh_token
from application.service.login import service_login, out_login, account_check, my_services
from application.service.reg import service_reg
from application.service.role import role_list, create_role, del_role, update_role, change_status
from application.service.role import sys_rule, set_scopes, get_role_rule
from application.service.service import service_info
from application.service.user import create_admin, current_user, admin_list, get_admin_role, delete_user
from application.service.user import admin_user_role, update_admin_user
from extends.wechat.wechat import user_wechat_bind, create_qrcode_url, call, wechat_confirm, check_scan

service = APIRouter(prefix="/api/v1")

service.get("/wechat/qrcode", tags=["服务商"], summary="获取微信授权二维码")(create_qrcode_url)
service.get("/wechat/get/user", tags=["服务商"], summary="拉取微信用户信息")(call)
service.get("/wechat/user/confirm", tags=["服务商"], summary="微信用户操作确认")(wechat_confirm)
service.get("/wechat/check_scan",  tags=["服务商"], summary="微信扫码状态检测")(check_scan)
service.get("/service/outLogin", tags=["服务商"], summary="退出登陆")(out_login)
service.get("/service/my/services", tags=["服务商"], summary="用户服务商获取")(my_services)
service.post("/service/account/check", tags=["服务商"], summary="用户账户验证")(account_check)
service.post("/service/reg",  tags=["服务商"], summary="服务商注册")(service_reg)
service.post("/service/login", tags=["服务商"], name="服务商登录")(service_login)


service.get(
    path="/service/token/refresh_token",
    tags=["服务商"],
    name="token刷新",
    dependencies=[Security(permissions)]
)(refresh_token)


service.get(
    path="/service/info",
    tags=["服务商管理"],
    summary="当前服务商信息",
    dependencies=[Security(permissions, scopes=["service_info"])]
)(service_info)


service.get(
    path="/service/current/user",
    tags=["用户管理"],
    summary="当前用户信息",
    dependencies=[Security(permissions, scopes=["user_info"])]
)(current_user)



service.post(
    path="/service/admin/create",
    tags=["用户管理"],
    summary="管理员添加",
    dependencies=[Security(permissions, scopes=["admin_user_add"])]
)(create_admin)

service.get(
    path="/service/admin/list",
    tags=["管理员"],
    summary="管理员列表",
    name="name",
    dependencies=[Security(permissions, scopes=["admin_user"])]
)(admin_list)

service.get(
    path="/service/admin/role",
    tags=["管理员"],
    summary="服务商管理员角色",
    dependencies=[Security(permissions)]
)(get_admin_role)

service.get(
    path="/service/admin/delete",
    tags=["管理员"],
    summary="管理员删除",
    dependencies=[Security(permissions, scopes=["admin_user_del"])]
)(delete_user)

service.get(
    path="/service/admin/user/role",
    tags=["管理员"],
    summary="获取管理员对应角色",
    dependencies=[Security(permissions, scopes=["admin_user_update"])]
)(admin_user_role)

service.get(
    path="/service/admin/user/wechat",
    tags=["管理员"],
    summary="管理员微信绑定二维码链接",
    dependencies=[Security(permissions, scopes=["admin_user_update"])]
)(user_wechat_bind)

service.post(
    path="/service/admin/user/update",
    tags=["管理员"],
    summary="更新管理员用户",
    dependencies=[Security(permissions, scopes=["admin_user_update"])]
)(update_admin_user)



service.get(
    path="/service/role/list",
    tags=["角色管理"],
    summary="角色列表",
    dependencies=[Security(permissions, scopes=["admin_role"])]
)(role_list)

service.post(
    path="/service/role/create",
    tags=["角色管理"],
    summary="角色创建",
    dependencies=[Security(permissions, scopes=["admin_role_add"])]
)(create_role)

service.get(
    path="/service/role/delete",
    tags=["角色管理"],
    summary="角色删除",
    dependencies=[Security(permissions, scopes=["admin_role_delete"])]
)(del_role)

service.post(
    path="/service/role/update",
    tags=["角色管理"],
    summary="角色更新",
    dependencies=[Security(permissions, scopes=["admin_role_update"])]
)(update_role)

service.post(
    path="/service/role/change",
    tags=["角色管理"],
    summary="角色状态更新",
    dependencies=[Security(permissions, scopes=["admin_role_update"])]
)(change_status)

service.get(
    path="/service/rule/list",
    tags=["角色管理"],
    summary="系统权限列表",
    dependencies=[Security(permissions, scopes=["admin_role_update"])]
)(sys_rule)

service.post(
    path="/service/set/scopes",
    tags=["角色管理"],
    summary="权限分配",
    dependencies=[Security(permissions, scopes=["admin_role_update"])]
)(set_scopes)

service.get(
    path="/service/get/role",
    tags=["角色管理"],
    summary="角色及权限查询",
    dependencies=[Security(permissions, scopes=["admin_role_update"])]
)(get_role_rule)
